# -*- coding: utf-8 -*-

# Copyright (c) Huoty, All rights reserved
# Author: Huoty <sudohuoty@163.com>
# CreateTime: 2020-09-14 19:11:49

import operator
import itertools


def inext(iterator):
    if hasattr(iterator, "next"):
        return iterator.next()
    else:
        return next(iterator)


class Field(object):
    _counter = itertools.count()
    def __init__(self):
        self.count = inext(Field._counter)
        self.name = ''
    def __repr__(self):
        return "Field(%r)" % self.name

class MyForm(object):
    b = Field()
    a = Field()
    c = Field()

    def __init__(self):
        self.fields = []
        for field_name in dir(self):
            field = getattr(self, field_name)
            if isinstance(field, Field):
                field.name = field_name
                self.fields.append(field)
        self.fields.sort(key=operator.attrgetter('count'))

m = MyForm()
print(m.fields)  # in defined order
